package com.hemerasolutions.v2trainer.model.exercise.intensity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import com.hemerasolutions.v2trainer.model.base.BaseModel;
import com.hemerasolutions.v2trainer.model.exercise.Exercise;
import com.hemerasolutions.v2trainer.model.exercise.executions.Execution;

@Entity
public class IntensityExecution extends BaseModel {

	private static final long serialVersionUID = 1L;

    @ManyToOne
    private Execution execution;
    
    @ManyToOne
    private Exercise exercise;
    
    @OneToMany(mappedBy="intensityExecution", cascade=CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval=true)
    private List<IntensityTable> intensityTables;

    
	public IntensityExecution() {
		super();
		this.intensityTables = new ArrayList<IntensityTable>();
	}


	public IntensityExecution(Exercise exercise, Execution ex){
		super();
		this.setExercise(exercise);
		this.setExecution(ex);
		this.setIntensityTables(new ArrayList<IntensityTable>());
	}
		
	public IntensityExecution(IntensityExecution other, Exercise exercise){
		super();
		this.execution = other.execution;
		this.exercise = exercise;
		this.intensityTables = new ArrayList<IntensityTable>();
		for(IntensityTable it:other.intensityTables){
			this.intensityTables.add(new IntensityTable(it,this));
		}
	}

	public Execution getExecution() {
		return execution;
	}

	public void setExecution(Execution execution) {
		this.execution = execution;
	}

	public List<IntensityTable> getIntensityTables() {
		return intensityTables;
	}

	public void setIntensityTables(List<IntensityTable> intensityTables) {
		this.intensityTables = intensityTables;
	}

	public Exercise getExercise() {
		return exercise;
	}

	public void setExercise(Exercise exercise) {
		this.exercise = exercise;
	}


	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((execution == null) ? 0 : execution.hashCode());
		result = prime * result
				+ ((exercise == null) ? 0 : exercise.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}


	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		IntensityExecution other = (IntensityExecution) obj;
		if (execution == null) {
			if (other.execution != null) {
				return false;
			}
		} else if (!execution.equals(other.execution)) {
			return false;
		}
		if (exercise == null) {
			if (other.exercise != null) {
				return false;
			}
		} else if (!exercise.equals(other.exercise)) {
			return false;
		}
		if (id == null) {
			if (other.id != null) {
				return false;
			}
		} else if (!id.equals(other.id)) {
			return false;
		}
		return true;
	}


	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "IntensityExecution [id=" + id + ", execution=" + execution
				+ ", exercise=" + exercise + "]";
	}




    

}

